home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / UNIXTOOL / UNIXLIB37B / !UnixLib37_src_signal_c_coredump < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-09  |  3.8 KB  |  171 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/signal/c/RCS/coredump,v $
  4.  * $Date: 1996/11/06 22:01:42 $
  5.  * $Revision: 1.2 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: coredump,v $
  10.  * Revision 1.2  1996/11/06 22:01:42  unixlib
  11.  * Yet more changes by NB, PB and SC.
  12.  *
  13.  * Revision 1.1  1996/10/30 21:57:16  unixlib
  14.  * Initial revision
  15.  *
  16.  ***************************************************************************/
  17.  
  18. static const char rcs_id[] = "$Id: coredump,v 1.2 1996/11/06 22:01:42 unixlib Rel $";
  19.  
  20. /* signal.c.coredump. Write out core dump/termination diagnostic
  21.    information for a process. */
  22.  
  23. /* This source file should be compiled with stack checking turned off.
  24.    Ideally they should be re-written in assembler.  */
  25.  
  26. #include <unixlib/sigstate.h>
  27. #include <sys/unix.h>
  28. #include <sys/syslib.h>
  29. #include <sys/swis.h>
  30. #include <sys/os.h>
  31.  
  32. #pragma no_check_stack
  33.  
  34. static char *__rname[16] =
  35. {
  36.   "a1", "a2", "a3", "a4",
  37.   "v1", "v2", "v3", "v4", "v5", "v6",
  38.   "sl", "fp", "ip", "sp", "lr", "pc"
  39. };
  40.  
  41. struct trace
  42.   {
  43.   unsigned int    *fp;
  44.   unsigned int    *sp;
  45.   unsigned int    *lr;
  46.   unsigned int    *pc;
  47.   };
  48.  
  49.  
  50. void
  51. __backtrace (register unsigned int *fp)
  52. {
  53.   struct trace *f;
  54.   unsigned int *pc;
  55.   int i;
  56.   char *n;
  57.   int features;
  58.   int regs[10];
  59.   register struct env *e;
  60.  
  61.   /* Remove environment handlers.  */
  62.   e = __Oenv;
  63.   for (i = 0; i < 13; i++)
  64.     if (i != 11)  /* Do not remove exit handler. */
  65.       __wrenv (i, e->h + i);
  66.  
  67.   os_print ("\rstack backtrace:\r\n\n");
  68.  
  69.   regs[0] = 0;
  70.   /* If SWI returns an error then assume unknown and thus not StrongARM.  */
  71.   if (os_swi (OS_PlatformFeatures, regs))
  72.     features = 0;
  73.   else
  74.     features = regs[0];
  75.  
  76.  
  77.   while (fp)
  78.     {
  79.       f = (struct trace *) (fp - 3);
  80.       pc = (unsigned int *) ((unsigned int) f->pc & 0x03fffffcU);
  81.       /* Bit 3 of features set => stored PC is PC+8 rather than PC+12. */
  82.       if (features & 0x08)
  83.         pc++;
  84.       if ((unsigned int) (f->fp) & 0x80000000U)
  85.     {
  86.       os_print ("\r\n\n pc: ");
  87.       os_prhex ((int) pc);
  88.       os_print (" sp: ");
  89.       os_prhex ((int) f->sp);
  90.       n = "?";        /* SJC */
  91.       for (i = -3; i > -7; i--)
  92.         if ((pc[i] & 0xffffff00U) == 0xff000000U)
  93.           {
  94.         n = (char *) (pc + i) - (pc[i] & 0xffU);
  95.         break;
  96.           }
  97.       os_print (" ");
  98.       os_print (n);        /* SJC */
  99.       os_print ("()\r\n");
  100.       fp++;
  101.       os_print ("\r\nRegister dump:\r\n");
  102.       for (i = 0; i < 16; i++)
  103.         {
  104.           if (!(i & 3))
  105.         os_print ("\r\n ");
  106.           os_print (__rname[i]);
  107.           os_print (": ");
  108.           os_prhex (fp[i]);
  109.           os_print (" ");
  110.         }
  111.       os_print ("\r\n\n\n");
  112.       fp = (unsigned int *) ((unsigned int) (f->fp) & ~0x80000000U);
  113.     }
  114.       else
  115.     {
  116.       n = "?";
  117.       for (i = -3; i > -7; i--)
  118.         if ((pc[i] & 0xffffff00U) == 0xff000000U)
  119.           {
  120.         n = (char *) (pc + i) - (pc[i] & 0xffU);
  121.         break;
  122.           }
  123.       os_print (" pc: ");
  124.       os_prhex ((int) pc);
  125.       os_print (" sp: ");
  126.       os_prhex ((int) f->sp);
  127.       os_print (" ");
  128.       os_print (n);
  129.       os_print ("()\r\n");
  130.       fp = f->fp;
  131.     }
  132.     }
  133.   os_print ("\r\n");
  134.  
  135.   /* reinstall handlers */
  136.   e = __Cenv;
  137.   for (i = 0; i < 13; i++)
  138.     __wrenv (i, e->h + i);
  139. }
  140.  
  141. int
  142. __write_corefile (int signo, int sigcode, int sigerror)
  143. {
  144.   os_print ("\n\rFatal signal received: ");
  145.   os_print (sys_siglist[signo]);
  146. #if 0
  147.   os_print ("\n\rsignal code = 0x");
  148.   os_prhex (sigcode);
  149.   os_print ("   signal error = 0x");
  150.   os_prhex (sigerror);
  151. #else
  152.   sigcode = sigcode;
  153.   sigerror = sigerror;
  154. #endif
  155.   os_print ("\n\rA core dump will now follow ...\n\r");
  156.  
  157.   /* Do a core-dump.  */
  158.   __core ();
  159.   return 1;
  160. }
  161.  
  162. void
  163. __write_termination (int signo, int sigcode, int sigerror)
  164. {
  165.   os_print ("\n\rTermination signal received: ");
  166.   os_print (sys_siglist[signo]);
  167.   os_print ("\n\r");
  168.   sigcode = sigcode;
  169.   sigerror = sigerror;
  170. }
  171.